Total Complexity | 4 |
Total Lines | 28 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | interface InputEvent extends Event { |
||
2 | target: HTMLInputElement; |
||
3 | } |
||
4 | |||
5 | interface SubmitButton extends HTMLElement { |
||
6 | removeAttribute(name: string): void; |
||
7 | setAttribute(name: string, value: string): void; |
||
8 | } |
||
9 | |||
10 | /** |
||
11 | * checkValidText is where we check if the text input is valid |
||
12 | * If it is, we enable the submit button |
||
13 | */ |
||
14 | const checkValidText = (event: InputEvent): void => { |
||
15 | const bilInformasjon = event.target.value; |
||
16 | const submitButton = window.document.getElementById( |
||
17 | "submitButton" |
||
18 | ) as SubmitButton; |
||
19 | |||
20 | const letters = /[A-Z]{2}\d{5}/gi; |
||
21 | const bilInformasjonMatchesFormat = letters.test(bilInformasjon); |
||
22 | |||
23 | if ( |
||
24 | bilInformasjonMatchesFormat && |
||
25 | bilInformasjon !== undefined && |
||
26 | bilInformasjon.length === 7 |
||
27 | ) { |
||
28 | submitButton.removeAttribute("disabled"); |
||
29 | } else { |
||
35 |